﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MusicDatabase
{
    /*
     * Auteur:  Joris Molnár en Niels van Leusden
     * Datum:   31-1-2013
     * Omschrijving: Na openen van het Register scherm via Login, zorgt deze klasse voor
     *               Het aanmaken van een nieuwe user, via de klasse User, wanneer alle gegevens kloppen.
     * 
     */
    public partial class Register : Form
    {
        public Register()
        {
            InitializeComponent();
        }
        
        private void textBox_TextChanged(object sender, EventArgs e)
        {
            if (txtFName.Text.Trim() != "" && txtLName.Text.Trim() != "" && txtUserName.Text.Trim() != "" && txtPass.Text != "" && txtPassVerify.Text != "" && txtEmail.Text.Trim() != "")
            {
                btnCreate.Enabled = true;
            }
            else
            {
                btnCreate.Enabled = false;
            }
        }

        /// <summary>
        /// Creates a new user, what else is there to say?
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCreate_Click(object sender, EventArgs e)
        {
            txtFName.Text = txtFName.Text.Trim();
            txtLName.Text = txtLName.Text.Trim();
            txtUserName.Text = txtUserName.Text.Trim();
            txtDescr.Text = txtDescr.Text.Trim();
            txtEmail.Text = txtEmail.Text.Trim();

            if (txtPass.Text == txtPassVerify.Text)
            {
                if (txtEmail.Text.Contains('@') && txtEmail.Text.Contains('.'))
                {
                    string[] userData = { "", txtUserName.Text, txtPass.Text, txtFName.Text, txtLName.Text, txtEmail.Text, txtDescr.Text, DateTime.Now.ToShortDateString() };
                    User user = new User(userData);
                    user.Save();
                    this.Close();
                }
                else
                {
                    MessageBox.Show("E-Mail Adress is not valid", "Problem", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txtEmail.Text = "";
                }
            }
            else
            {
                MessageBox.Show("Your Passwords do not match", "Problem", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtPass.Text = "";
                txtPassVerify.Text = "";
            }
        }
    }
}
